package com.common.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * 发送短信类
 * @author yujunbo
 *
 */
public class SysSendUtil {
	public static void testPost(String phoneNum,String code) throws IOException 
	{
		/*String code = "1234";
		String phoneNum = "17603021475";*/
		URL url = new URL("http://www.lanz.net.cn/LANZGateway/DirectSendSMSs.asp");
		HttpURLConnection connection = (HttpURLConnection) url.openConnection();
		connection.setRequestMethod("POST");
		connection.setDoOutput(true);
		connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
		OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "GB2312");

		String urlString = "UserID=709793&" + "Account=15219460470&"
				+ "Password=421BD3C8FCFB5B3A525AD500B81184D1BCD6E077&" + "Content=您的注册验证码为" + code
				+ "，该验证码10分钟内有效。如非本人操作请忽略此短信！【浪驰软件】" + "&Phones=" + phoneNum + "&ReturnXJ=1";

//		System.out.println(urlString);
		urlString = urlString.replace("%", "％");
		urlString = urlString.replace("+", "＋");
		urlString = urlString.replace(" ", "+");

		out.write(urlString);
		out.flush();
		out.close();

		String sCurrentLine;
		String sTotalString;
		sCurrentLine = "";
		sTotalString = "";
		InputStream l_urlStream;
		l_urlStream = connection.getInputStream();
		BufferedReader l_reader = new BufferedReader(new InputStreamReader(l_urlStream));
		while ((sCurrentLine = l_reader.readLine()) != null) {
			sTotalString += sCurrentLine + "\r\n";
		}
//		System.out.println(sTotalString.toString());
	}
}
